package day0225;

import java.util.Arrays;
import java.util.Scanner;

public class Test5 {
    public static void main(String[] args) {
        String[]   mps = {""  ,"" ,""};
        int []   ranAnswers = {0  ,0 ,0};
        Test5.createMathExpressions(mps,ranAnswers);//1.createMathExpressions:生成三个数学公式
        System.out.println(Arrays.toString(mps));

        int[]   userAnswers = {0  ,0 ,0};
        Test5.inputUserAnswers(userAnswers);//2输入答案存入到数组返回数组
        int c=Test5.matchAnswers(ranAnswers,userAnswers);//3.输入答案存入到数组返回数组
        System.out.println("回答对的数目："+c);
    }

    static int matchAnswers(int []  ras, int[]  uas){
        int rightCount=0;
        for (int i = 0; i < ras.length ; i++) {
            if(ras[i] ==uas[i]){
                rightCount++;
            }
        }
        return rightCount;
    }



    static void inputUserAnswers(int[]  uas){
        Scanner s=new Scanner(System.in);
        for (int i = 0; i < uas.length; i++) {
            System.out.println("请输入第" + i +"道题的答案：");
            uas[i]=s.nextInt();
        }
    }


    static void createMathExpressions(String[]  mps1,int[] ras){
        for (int i = 0; i < mps1.length; i++) {
            int ranNum=(int)(Math.random()*5);
            int n1=(int)(Math.random()*99+1);  //[1,99]
            int n2=(int)(Math.random()*99+1);  //[1,99]
            switch(ranNum){
                case 0:  mps1[i] = n1+ "+" + n2  +"="; ras[i]=n1+n2;break;
                case 1:  mps1[i] = n1+ "-" + n2  +"="; ras[i]=n1-n2;break;
                case 2:  mps1[i] = n1+ "*" + n2  +"="; ras[i]=n1*n2;break;
                case 3:  mps1[i] = n1+ "/" + n2  +"="; ras[i]=n1/n2;break;
                case 4:  mps1[i] = n1+ "%" + n2  +"="; ras[i]=n1%n2;break;
            }
        }
    }

}
